/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.sunspotworld.mydatawrappers;

import com.sun.spot.peripheral.Spot;
import com.sun.spot.util.IEEEAddress;
import java.util.Date;
import org.sunspotworld.sensortasks.TimeKeeper;

/**
 *
 * @author me
 */
public class PowerPacket extends TrackingPacket {
    public static final String HEADER = "Date\tTime\tNode\tCapacity(mAh)";
    public static final int SIZE = TrackingPacket.SIGN_SIZE + 8;
    private double capacity;

    public PowerPacket(double Power) {
        super.type = super.POWER_PACKET;
        super.senderAddress = Spot.getInstance().getRadioPolicyManager().getIEEEAddress();
        capacity = Power;
        super.timestamp = TimeKeeper.getInstance().currentTimeMillis();
    }   
    
    protected PowerPacket(byte[] b, int index) {
        super.readSign(b, index);
        int Power = super.SIGN_SIZE + index;
        capacity = super.byteArrayToDouble(b, Power);
    }
    
    public int getSize() {
        return SIZE;
    }

    public String printEntryLine() {
        Date time = new Date(super.timestamp);
        //SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd '\t' HH:mm:ss.SSS");
        return time + "\t" + new IEEEAddress(super.senderAddress).asDottedHex() + "\t" + capacity;
    }

    public byte[] toByteArray() {
        byte[] b = new byte[getSize()];
        int i;
        super.sign(b);
        int temp = super.SIGN_SIZE;
        byte[] tempArray = super.doubleToByteArray(capacity);
        for (i=0; i<tempArray.length; i++) {
            b[temp] = tempArray[i];
            temp++;
        }
        return b;
    }

}
